import fetch from "@/api/fetch"
import qs from "qs";
import constants from "@/api/constants"

const baseURL = constants.baseURL + "/order";

const api = {
    // 订单
    order: {
        // 分页列表
        listPage(params) {
            return fetch.get(baseURL + "/api/front/listPage", {
                params: params,
                paramsSerializer: function (params) {
                    return qs.stringify(params, { arrayFormat: "repeat" });
                }
            });
        },
        info(id) {
            return fetch.get(baseURL + "/api/front/info/" + id);
        },
        infoByOrderSn(orderSn) {
            return fetch.get(baseURL + "/api/front/infoByOrderSn/" + orderSn);
        },
        // 库存检查
        stockCheck(skuQuantityList) {
            return fetch.post(baseURL + "/order/stockCheck", skuQuantityList);
        },
        // 订单确认
        confirm(addressId, skuQuantityList) {
            return fetch.post(baseURL + "/order/confirm", {
                addressId: addressId,
                skuQuantityList: skuQuantityList
            });
        },
        // 提交订单
        submit(params) {
            return fetch.post(baseURL + "/order/submit", params);
        },
        // 支付宝手机网站支付
        aliMobileWapPay(orderId, returnUrl) {
            return fetch.post(baseURL + "/order/aliMobileWapPay?orderId=" + orderId + "&returnUrl=" + returnUrl);
        },
        // 确认收货
        takeDelivery(id) {
            return fetch.post(baseURL + "/order/takeDelivery/" + id);
        },
        // 删除订单
        deleteOrder(id) {
            return fetch.post(baseURL + "/order/deleteOrder/" + id);
        },

    },
    refund: {
        // 售前退款
        applyRefund(params) {
            return fetch.post(baseURL + "/refund/applyRefund/", params);
        },
        // 售后退款
        applyReturn(params) {
            return fetch.post(baseURL + "/refund/applyReturn/", params);
        },
        // 退货发货
        returnDelivery(params) {
            return fetch.post(baseURL + "/refund/returnDelivery", params);
        },
    },
    member: {
        // 不同状态订单数量
        orderNumStatistics(memberId) {
            return fetch.get(baseURL + "/api/front/orderNumStatistics/" + memberId);
        }
    }
}

export default api;